
Ext.define('Avrio.store.Device_Type', {
    extend: 'Ext.data.Store',

    model: 'Avrio.model.Device_Type',

    autoDestroy: true,
    pageSize: 15,
    autoSync: true,
    remoteSort: true,
    
    //storeId: 'myperson', // Ext.getStore('myperson')

    proxy: {
        type: 'ajax',
        api: {
            read:    '/avrio/get?do=devicetype&ex=read',    // store.load(); 
            update:  '/avrio/get?do=devicetype&ex=update',  //
            create:  '/avrio/get?do=devicetype&ex=create',  // store.add(Ext.create('MyApp.model.SomeModel'));
            destroy: '/avrio/get?do=devicetype&ex=delete'   // store.remove(myStore.first()); store.sync();
        },
        reader: {
            type: 'json',
            root: 'data',
            successProperty: 'success',
            totalProperty: 'total'
        },
        listeners: {
            exception: function(proxy, response, operation){
                Ext.MessageBox.show({
                    title: 'Ajax Exception',
                    msg:  'proxy: ' + proxy +
                          '\nresponse: ' + response +
                          '\noperation: ' + operation.getError(),
                    icon: Ext.MessageBox.ERROR,
                    buttons: Ext.Msg.OK
                });
            }
        },
        simpleSortMode: true
    },
    listeners: {
        write: function(store, operation) {
            var id = Ext.JSON.decode(operation.response.responseText).id;
            if(id) {
                store.data.items[0].data.id = id; // new record add real id
            }
        }
    }
});
